package servlet3;

import com.google.gson.Gson;
import dao.DB;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;


//添加好友的信息
@WebServlet("/seleaddfri")
public class addfriServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String acc = req.getParameter("acc");
        List list2 = DB.executeQuery("SELECT * FROM `user` WHERE account= ?" ,acc);
        if (list2.size() ==0){
            req.getSession().setAttribute("addmsg","没有该用户！");
            resp.sendRedirect("/page.jsp");
        }

        UserService userSer =new UserService();
        List fri = userSer.getAddfriend(acc);
//        req.setAttribute("jhe",fri);
        resp.getWriter().print(new Gson().toJson(fri));
//        resp.sendRedirect("page.jsp");
    }
}
